package org.geektimes.common.util;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @FileName: PropertiesUtil
 * @Description: properties工具类
 * @Author: MaWenHao
 * @Created: 2021/2/28 - 下午9:43
 */
public final class PropertiesUtil {

    public static Properties loadPropertyFile(String fileName) {
        if (null == fileName || fileName.equals("")) {
            throw new IllegalArgumentException("Properties file path can not be null: " + fileName);
        }

        try (InputStream inputStream = PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName)) {
            Properties properties = new Properties();
            properties.load(inputStream);
            return properties;
        } catch (FileNotFoundException e) {
            throw new IllegalArgumentException("Properties file not found: " + fileName);
        } catch (IOException e) {
            throw new IllegalArgumentException("Properties file can not be loading: " + fileName);
        }
    }
}
